package com.zhou.plugin.packagejars.message;

import com.intellij.compiler.impl.ProblemsViewPanel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.MessageView;

/**
 * Created by Administrator on 2016/7/8.
 */

public class Messages {
	private static final String ID = "packing";

	public Messages() {
	}

	private static ProblemsViewPanel getInstance(Project project) {
		MessageView messageView = MessageView.SERVICE.getInstance(project);
		ProblemsViewPanel packMessages = null;
		Content[] content = messageView.getContentManager().getContents();
		int len$ = content.length;

		for (Content content1 : content) {
			if ("packing".equals(content1.getTabName())) {
				packMessages = (ProblemsViewPanel) content1.getComponent();
				break;
			}
		}

		if (packMessages != null) {
			return packMessages;
		} else {
			packMessages = new ProblemsViewPanel(project);
			Content var7 = com.intellij.ui.content.ContentFactory.SERVICE.getInstance().createContent(packMessages, "packing", true);
			messageView.getContentManager().addContent(var7);
			messageView.getContentManager().setSelectedContent(var7);
			return packMessages;
		}
	}

	public static void clear(Project project) {
		MessageView messageView = MessageView.SERVICE.getInstance(project);
		Content[] arr$ = messageView.getContentManager().getContents();
		int len$ = arr$.length;

		for (Content content : arr$) {
			if ("packing".equals(content.getTabName())) {
				ProblemsViewPanel viewPanel = (ProblemsViewPanel) content.getComponent();
				viewPanel.close();
				break;
			}
		}

	}

	public static void info(Project project, String string) {
		ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
		if (toolWindow != null) {
			toolWindow.activate((Runnable) null, false);
		}

		getInstance(project).addMessage(3, new String[]{string}, (VirtualFile) null, -1, -1, (Object) null);
	}
}
